<?php
/**
 * User: b179a9
 * Date: 10/13/11
 * Time: 6:30 PM
 */

class App_Form_Quest_Form extends Zend_Form
{

    public function init()
    {
        $this->setAction('');
        $this->setMethod('post');
        $this->setAttrib('enctype', 'multipart/form-data');

        $id = new Zend_Form_Element_Hidden('id');
        $this->addElement($id);

        $title = new Zend_Form_Element_Text('title');
        $title->setRequired()
                ->setLabel('Title:')
                ->setAttrib('class', 'text-input small-input');
        $this->addElement($title);

        $dateStart = new Zend_Form_Element_Text('datestart');
        $dateStart->setRequired()
                ->setLabel('Quest starts:')
                ->addValidator(new Zend_Validate_Date())
                ->setAttrib('class', 'text-input small-input datepicker');
        $this->addElement($dateStart);

        $dateEnd = new Zend_Form_Element_Text('dateend');
        $dateEnd->setRequired()
                ->setLabel('Quest ends:')
                ->addValidator(new Zend_Validate_Date())
                ->setAttrib('class', 'text-input small-input datepicker');
        $this->addElement($dateEnd);

        $answer = new Zend_Form_Element_Text('answer');
        $answer->setRequired()
                ->setLabel('Answer to quest:')
                ->addFilter(new Zend_Filter_StringTrim())
                ->setAttrib('class', 'text-input small-input');
        $this->addElement($answer);

        $price = new Zend_Form_Element_Text('price');
        $price->setRequired()
                ->setLabel('Price:')
                ->addValidator(new Zend_Validate_Digits())
                ->setAttrib('class', 'text-input small-input');
        $this->addElement($price);

        $postal = new Zend_Form_Element_Text('postal');
        $postal->setRequired()
                ->setLabel('Postal code:')
                ->addValidator(new Zend_Validate_Digits())
                ->setAttrib('class', 'text-input small-input');
        $this->addElement($postal);

        $description = new Zend_Form_Element_Textarea('description');
        $description->setRequired()
                ->setLabel('Description:');
        $this->addElement($description);

        $prize = new Zend_Form_Element_Textarea('prize');
        $prize->setRequired()
            ->setLabel('Prize:');
        $this->addElement($prize);

        $img = new Zend_Form_Element_File('img');
        $img->setLabel('Image:')
                ->setDestination(dirname(APPLICATION_PATH) . '/public/maps_source/');
        $this->addElement($img);

        $file = new Zend_Form_Element_File('file');
        $file->setLabel('File:')
                ->setDestination(dirname(APPLICATION_PATH) . '/public/maps_files/');
        $this->addElement($file);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save')
                ->setAttrib('class', 'button');
        $this->addElement($submit);
    }

    public function populate($values)
    {
        $values['datestart'] = $values['datestart']->format('Y-m-d');
        $values['dateend'] = $values['dateend']->format('Y-m-d');
        parent::populate($values);
    }

}
